package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.ShopDealer;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.dao.ShopDealerMapper;
import com.yami.shop.service.ShopDealerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ShopDealerServiceImpl extends ServiceImpl<ShopDealerMapper, ShopDealer> implements ShopDealerService {
    @Autowired
    ShopDealerMapper shopDealerMapper;

    @Override
    public ShopDealer getShopDealerById(Integer id) {
        return shopDealerMapper.selectByPrimaryKey(id);
    }

    @Override
    public IPage<ShopDealer> getShopDealerPage(PageParam<ShopDealer> page, ShopDealer shopDealer) {
        LambdaQueryWrapper<ShopDealer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShopDealer::getShopId, shopDealer.getShopId());
        queryWrapper.orderByDesc(ShopDealer::getCreateTime);
        return shopDealerMapper.selectPage(page, queryWrapper);
    }

    @Override
    public int updateShopDealerStatus(Integer id, String status) {
        ShopDealer shopDealer = new ShopDealer();
        shopDealer.setId(id);
        shopDealer.setStatus(status);
        return shopDealerMapper.updateById(shopDealer);
    }

    @Override
    public int updateShopDealer(ShopDealer shopDealer) {
        return shopDealerMapper.updateByPrimaryKeySelective(shopDealer);
    }

    @Override
    public int addShopDealer(ShopDealer shopDealer) {
        return shopDealerMapper.insertSelective(shopDealer);
    }
}
